﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmartMeterParamFrame.Model.DIValueConverters
{
    /// <summary>
    /// 结算日1,2,3，转换类
    /// </summary>
    class Converter_JeiShuanRi : IDIDataConverter
    {
        static uint MIN = uint.Parse("04000B01", System.Globalization.NumberStyles.AllowHexSpecifier);
        static uint MAX = uint.Parse("04000B03", System.Globalization.NumberStyles.AllowHexSpecifier);

        public bool CanConverter(string di)
        {
            uint udi = uint.Parse(di, System.Globalization.NumberStyles.AllowHexSpecifier);

            if (udi >= MIN && udi <= MAX)
                return true;

            return false;
        }

        public string ConvertToUI(string di, string lowValue)
        {
            string newValue = lowValue.Substring(0, 2) + "-" + lowValue.Substring(2, 2);
            return newValue;
        }

        public string ConvertToLow(string di, string uiValue)
        {
            string[] vals = uiValue.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries);
            string newValue = null;

            if (vals.Length != 2)
                throw new ArgumentException();
            foreach (string s in vals)
                newValue += s.PadLeft(2, '0');
            return newValue;
        }

        public bool ValidateValue(string di, string value)
        {
            throw new NotImplementedException();
        }
    }
}
